package com.qfedu.aunt.commons.controller;


import com.qfedu.aunt.commons.pojo.Role;
import com.qfedu.aunt.commons.result.R;
import com.qfedu.aunt.commons.service.RoleService;
import com.qfedu.aunt.commons.vo.RoleAddVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaobobo
 * @since 2022-10-31
 */
@RestController
@RequestMapping("/aunt/commons/role")
@Api(description = "角色模块",tags = "角色模块")
public class RoleController {

    @Autowired
    private RoleService roleService;
    /**
     * 查询所有的角色
     * @return
     */
    @ApiOperation(value = "查询所有的角色")
    @GetMapping("/findAllRole")
    @ApiImplicitParam(name = "token",value = "用户身份标识",dataType = "string",paramType = "header",required = true)
    public R findAllRole(){
        List<Role> roleList=roleService.findAllRole();
        return R.ok().setData("roleList",roleList);
    }


    /**
     * 添加角色
     * @param roleAddVo
     * @return
     */
    @ApiOperation("添加角色")
    @ApiImplicitParam(name = "token",value = "用户身份标识",dataType = "string",paramType = "header",required = true)
    @PostMapping("/addRole")
    public R addRole(@RequestBody RoleAddVo roleAddVo) throws InvocationTargetException, IllegalAccessException {
        roleService.addRole(roleAddVo);
        return R.ok();
    }



}

